package com.ruoyi.teaching.service.impl;

import java.util.List;

import com.ruoyi.teacher.domain.MyTask;
import com.ruoyi.teacher.domain.Task;
import com.ruoyi.teacher.mapper.MyTaskMapper;
import com.ruoyi.teacher.mapper.TaskMapper;
import com.ruoyi.teaching.dto.ParameterIdDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teaching.mapper.BblRepeateMapper;
import com.ruoyi.teaching.domain.BblRepeate;
import com.ruoyi.teaching.service.IBblRepeateService;

/**
 * 留级学生名单Service业务层处理
 * lbj
 * @author ruoyi
 * @date 2023-05-19
 */
@Service
public class BblRepeateServiceImpl implements IBblRepeateService 
{
    @Autowired
    private BblRepeateMapper bblRepeateMapper;

    @Autowired
    private MyTaskMapper myTaskMapper;

    @Autowired
    private TaskMapper TaskMapper;
    /**
     * 查询留级学生名单
     * 
     * @param id 留级学生名单主键
     * @return 留级学生名单
     */
    @Override
    public BblRepeate selectBblRepeateById(Long id)
    {
        return bblRepeateMapper.selectBblRepeateById(id);
    }

    /**
     * 查询留级学生名单列表
     * 
     * @param bblRepeate 留级学生名单
     * @return 留级学生名单
     */
    @Override
    public List<BblRepeate> selectBblRepeateList(BblRepeate bblRepeate)
    {
        return bblRepeateMapper.selectBblRepeateList(bblRepeate);
    }

    /**
     * 新增留级学生名单
     * 
     * @param bblRepeate 留级学生名单
     * @return 结果
     */
    @Override
    public int insertBblRepeate(BblRepeate bblRepeate)
    {
        return bblRepeateMapper.insertBblRepeate(bblRepeate);
    }

    /**
     * 修改留级学生名单
     * 
     * @param bblRepeate 留级学生名单
     * @return 结果
     */
    @Override
    public int updateBblRepeate(BblRepeate bblRepeate)
    {
        return bblRepeateMapper.updateBblRepeate(bblRepeate);
    }

    /**
     * 批量删除留级学生名单
     * 
     * @param ids 需要删除的留级学生名单主键
     * @return 结果
     */
    @Override
    public int deleteBblRepeateByIds(Long[] ids)
    {
        return bblRepeateMapper.deleteBblRepeateByIds(ids);
    }

    /**
     * 删除留级学生名单信息
     * 
     * @param id 留级学生名单主键
     * @return 结果
     */
    @Override
    public int deleteBblRepeateById(Long id)
    {
        return bblRepeateMapper.deleteBblRepeateById(id);
    }

    @Override
    public int addTaskData(ParameterIdDto parameter) {
        Long id = parameter.getId();
        BblRepeate repeate = bblRepeateMapper.selectBblRepeateById(id);
        repeate.setRemark(parameter.getRemark());
        repeate.setTaskType(parameter.getTaskType());
        MyTask myTask = myTaskMapper.selectMyTaskById(parameter.getMytaskId());
        myTask.setTaskContent(parameter.getRemark());
        myTask.setCreateTime(parameter.getTaskTime());
        myTask.setTaskName(parameter.getStudent());
        myTask.setFinish(Integer.valueOf(parameter.getTaskType()));
        myTaskMapper.insertMyTask(myTask);
        Task tasks = TaskMapper.selectTaskByTaskContent(parameter.getRemark());
        if (tasks == null) {
            Task task = new Task();
            task.setContent(parameter.getRemark());
            task.setTitle("临时添加任务");
            task.setState(1);
            task.setGetCount(1);
//            task.setTeacherId(parameter.getTeacherId());
            TaskMapper.insertTask(task);
        }

        return 1;
    }
}
